#include "test.h"
using namespace std;


void Test_User::test_SD(void)
{
    User tmpUser(2, "悯醨", "123456", "测试用例");
    User tmpUser2;
    string tmpString = tmpUser.serialize();
    cout << "序列化之后的内容为:" << tmpString;
    tmpUser2.deSerialize(tmpString);
    cout << "反序列化之后:"
        << tmpUser2.getId()
        << tmpUser2.getName()
        << tmpUser2.getPassword()   
        << tmpUser2.getDescribe() << endl;
}

void Test_User::test_LS(void)
{
    UserManager tmpUserManager;
    User tmpUser(3, "悯醨", "123456", "测试用例");

    tmpUserManager.load_UserFromFile();

    auto it = tmpUserManager.getUserLib().back();
    tmpUser.setId((*it).getId() + 1);
    tmpUserManager.getUserLib().push_back(make_shared<User>(tmpUser));
    tmpUserManager.save_UserToFile();
}

void Test_User::test_login(void)
{
    UserManager tmpUserManager;
    shared_ptr<User> tmpSPtr;

    string tmpName;
    string tmpPd;

    tmpUserManager.load_UserFromFile();
    
    cout << "请输入用户名:";
    cin >> tmpName;
    cout << "请输入密码:";
    cin >> tmpPd;

    tmpSPtr = tmpUserManager.login_verification(tmpName, tmpPd);
    if (tmpSPtr == nullptr)
    {
        cout << "用户名或者密码错误！" << endl;
    }
    else
    {
        cout << (*tmpSPtr).serialize();
    }
}